home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / stdio / c / setbuf < prev    next >
Text File  |  1996-11-09  |  2KB  |  74 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/setbuf,v $
  4.  * $Date: 1996/11/06 22:01:42 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: setbuf,v $
  10.  * Revision 1.2  1996/11/06 22:01:42  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:32:42  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: setbuf,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
  19.  
  20. #include <errno.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23.  
  24. __STDIOLIB__
  25.  
  26.  
  27. /* If buf is null, this makes stream unbuffered.
  28.    Otherwise it makes stream fully buffered using buf
  29.    as the buffer (of size size).  */
  30. void
  31. setbuffer (FILE *stream, char *buf, size_t size)
  32. {
  33.   setvbuf (stream, buf, (buf) ? _IOFBF : _IONBF, size);
  34. }
  35.  
  36. /* Make stream be line buffered, and allocate the buffer.  */
  37.  
  38. void
  39. setlinebuf (FILE *stream)
  40. {
  41.   setvbuf (stream, NULL, _IOLBF, 0);
  42. }
  43.  
  44. void
  45. setbuf (register FILE * f, char *buf)
  46. {
  47.   setvbuf (f, buf, (buf) ? _IOFBF : _IONBF, BUFSIZ);
  48. }
  49.  
  50. int
  51. setvbuf (register FILE * f, register char *buf, register int flag,
  52.      register size_t bufsiz)
  53. {
  54.   if (f->flag & _IOREAD)
  55.     {
  56.       if (f->i_base)
  57.     return (-1);
  58.       f->i_ptr = f->i_base = (unsigned char *) buf;
  59.     }
  60.   else if (f->flag & _IOWRITE)
  61.     {
  62.       if (f->o_base)
  63.     return (-1);
  64.       f->o_ptr = f->o_base = (unsigned char *) buf;
  65.     }
  66.   else
  67.     return (-1);
  68.  
  69.   f->bufsiz = (!bufsiz) ? 1 : bufsiz;
  70.   f->flag = (f->flag & (~_IOBF)) | (flag & _IOBF);
  71.  
  72.   return (0);
  73. }
  74.